<template>
  <div class="float-ai-button" @click="openChat">
    <div class="ai-icon">
      <svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
      </svg>
    </div>
    <div v-if="showNotification" class="notification-badge"></div>
  </div>
</template>

<script>
export default {
  name: 'FloatAiButton',
  data () {
    return {
      showNotification: false
    }
  },
  mounted () {
    // 检查是否有未读消息（实际应用中从API获取）
    this.checkUnreadMessages()
  },
  methods: {
    openChat () {
      // 跳转到聊天页面
      this.$router.push('/ai-chat-view')
      this.showNotification = false
    },
    checkUnreadMessages () {
      // 模拟检查未读消息
      setTimeout(() => {
        this.showNotification = Math.random() > 0.5
      }, 2000)
    }
  }
}
</script>

<style scoped>
.float-ai-button {
  position: fixed;
  bottom: 50%;
  right: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9999;
  transition: all 0.3s ease;
  animation: pulse 2s infinite;
}

.float-ai-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.3);
}

.ai-icon {
  width: 32px;
  height: 32px;
  color: white;
}

.notification-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #ff4d4f;
  border: 2px solid white;
  animation: blink 1.5s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(26, 42, 108, 0.4); }
  70% { box-shadow: 0 0 0 12px rgba(26, 42, 108, 0); }
  100% { box-shadow: 0 0 0 0 rgba(26, 42, 108, 0); }
}

@keyframes blink {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* 响应式调整 */
@media (max-width: 768px) {
  .float-ai-button {
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
  }
}
</style>
